<template>
  <div class="source-video">
    <button class="explain" @click="videoModal = true">
      <label class="video-icon"></label>讲解
    </button>
    <Modal
      v-if="videoModal"
      @closeModal="videoModal = false"
      @cancel="videoModal = false"
    >
      <template #modalContent>
        <div class="video-content">
          <header class="video-content__header">
            <label class="close-icon" @click="videoModal = false"></label>
          </header>
          <VideoPlayer :url="props.url" :poster="getPoster"></VideoPlayer>
        </div>
      </template>
    </Modal>
  </div>
</template>
<script setup lang="ts">
import Modal from './Modal.vue'
import VideoPlayer from './VideoPlayer.vue'
import { ref, computed } from 'vue'
const videoModal = ref(false)
const props = defineProps({
  url: {
    default: '',
    type: String
  },
  poster: {
    default: '',
    type: String
  }
})

const getPoster = computed(() => {
  return `${props.url}?vframe/jpg/offset/1`
})
</script>
<style lang="less" scoped>
.source-video {
  .explain {
    width: 40px;
    padding: 8px;
    border-radius: 8px;
    background: #fff;
    color: #33caa4;
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    font-size: 22px;
    gap: 8px;
    justify-content: center;
    border: none;
    cursor: pointer;

    label {
      cursor: pointer;
      width: 24px;
      height: 24px;
      display: inline-block;
      background: url('@/assets/images/comment/video.png') no-repeat
        center/cover;
    }

    &:hover {
      background: #33caa4;
      color: #fff;

      label {
        background: url('@/assets/images/comment/video-active.png') no-repeat
          center/cover;
      }
    }
  }
  :deep(.mask) {
    .video-content {
      width: 1200px;
      height: 650px;
      border-radius: 24px;
      overflow: hidden;
      position: relative;
      display: flex;
      justify-content: center;

      &__header {
        position: absolute;
        top: 0;
        left: 0;
        height: 50px;
        width: 100%;
        border-radius: 24px 24px 0 0;
        z-index: 9999;
        background: rgba(0, 0, 0, 0.3);
        display: flex;
        align-items: center;
        justify-content: flex-end;

        .close-icon {
          cursor: pointer;
          display: inline-block;
          height: 24px;
          width: 24px;
          margin-right: 24px;
          background: url('@/assets/images/comment/close-modal.png') no-repeat
            center/cover;
          &:hover {
            opacity: 0.7;
          }
        }
      }
    }
    .modal-btn,
    .modal-top {
      display: none;
    }

    .modal {
      padding: 0;
    }
  }
}
</style>
